﻿using BigEgg.Framework.UnitTesting;
using FMStudio.Documents.TemplateDocument.Models;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using System.Collections.Generic;
using BigEgg.Framework.Foundation;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Linq;

namespace FMStudio.Documents.TemplateDocument.Test.Models
{
    [TestClass]
    public class TemplateContentTest
    {
        [TestMethod]
        public void GeneralTemplateContentTest()
        {
            MockTemplateContent content = new MockTemplateContent();

            Assert.IsNotNull(content.Items);
            Assert.AreEqual(0, content.Items.Count);
        }

        [TestMethod]
        public void PropertiesWithNotification()
        {
            MockTemplateContent content = new MockTemplateContent();

            AssertHelper.PropertyChangedEvent(content, x => x.Items,
                () => content.Items.Add(new Folder("SomeFolder")));
            Assert.AreEqual(1, content.Items.Count);
        }

        [TestMethod]
        public void ItemsTest()
        {
            MockTemplateContent content = new MockTemplateContent();
            Assert.IsNotNull(content.Items);

            content.Items.Add(new Folder("NewFolder"));
            content.Items.Add(new ProjectItem("NewDocument"));
            Assert.AreEqual(2, content.Items.Count);

            AssertHelper.PropertyChangedEvent(content, x => x.Items, () => content.Items.Add(new Folder("NewFolder2")));
            Assert.AreEqual(3, content.Items.Count);
        }

        [TestMethod]
        public void SerializationTest()
        {
            MockTemplateContent content = new MockTemplateContent();

            content.Items.Add(new Folder("SomeFolder"));
            content.Items.Add(new ProjectItem("Item"));

            XElement element = content.ObjectToXElement();
            MockTemplateContent newContent = element.XElementToObject<MockTemplateContent>();

            Assert.AreEqual(content.Items.Count, newContent.Items.Count);
        }

        public class MockTemplateContent : TemplateContent
        {
        }
    }
}
